package com.ruoyi.model.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.model.domain.vo.ModelAlgorithmVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.model.domain.ModelAlgorithm;
import com.ruoyi.model.service.IModelAlgorithmService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 模型算法管理Controller
 *
 * @author rww
 * @date 2024-11-25
 */
@RestController
@RequestMapping("/model/algorithm")
public class ModelAlgorithmController extends BaseController
{
    @Autowired
    private IModelAlgorithmService modelAlgorithmService;

    /**
     * 查询模型管理列表
     */
    @PreAuthorize("@ss.hasPermi('model:algorithm:list')")
    @GetMapping("/list")
    public TableDataInfo list(ModelAlgorithm modelAlgorithm)
    {
        startPage();
        List<ModelAlgorithm> list = modelAlgorithmService.selectModelAlgorithmList(modelAlgorithm);
        return getDataTable(list);
    }

    /**
     * 插叙模型列表-不带分页
     * **/

    @GetMapping("/noPageList")
    public AjaxResult noPageList(ModelAlgorithm modelAlgorithm)
    {
        List<ModelAlgorithm> list = modelAlgorithmService.selectModelAlgorithmList(modelAlgorithm);
        return AjaxResult.success(list);
    }

    /**
     * 导出模型管理列表
     */
    @PreAuthorize("@ss.hasPermi('model:algorithm:export')")
    @Log(title = "模型管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ModelAlgorithm modelAlgorithm)
    {
        List<ModelAlgorithm> list = modelAlgorithmService.selectModelAlgorithmList(modelAlgorithm);
        ExcelUtil<ModelAlgorithm> util = new ExcelUtil<ModelAlgorithm>(ModelAlgorithm.class);
        util.exportExcel(response, list, "模型管理数据");
    }

    /**
     * 获取模型管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('model:algorithm:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(modelAlgorithmService.selectModelAlgorithmVoById(id));
    }

    /**
     * 新增模型管理
     */
    @PreAuthorize("@ss.hasPermi('model:algorithm:add')")
    @Log(title = "模型管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ModelAlgorithm modelAlgorithm)
    {
        return toAjax(modelAlgorithmService.insertModelAlgorithm(modelAlgorithm));
    }

    @PreAuthorize("@ss.hasPermi('model:algorithm:set-param')")
    @Log(title = "模型管理", businessType = BusinessType.INSERT)
    @PostMapping("set-param")
    public AjaxResult setParam(@RequestBody ModelAlgorithmVo modelAlgorithm)
    {
        return toAjax(modelAlgorithmService.setModelAlgorithm(modelAlgorithm));
    }

    /**
     * 修改模型管理
     */
    @PreAuthorize("@ss.hasPermi('model:algorithm:edit')")
    @Log(title = "模型管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody ModelAlgorithm modelAlgorithm)
    {
        return toAjax(modelAlgorithmService.updateModelAlgorithm(modelAlgorithm));
    }

    /**
     * 删除模型管理
     */
    @PreAuthorize("@ss.hasPermi('model:algorithm:remove')")
    @Log(title = "模型管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(modelAlgorithmService.deleteModelAlgorithmByIds(ids));
    }
}
